﻿using FunArts.EasyDevOps.Shared.Models.Enums;
using FunArts.EasyDevOps.Shared.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunArts.EasyDevOps.Shared.Models.SshClient.Command
{
    public class QueryPorcessCommand : ILinuxCommand
    {
        /// <summary>
        /// 应用类型
        /// </summary>
        public AppRuntimeTypeEnum? AppRuntimeType { get; set; }
        /// <summary>
        /// 应用名称
        /// </summary>
        public string AppName { get; set; }
        public string BuildCommand(SystemVersionTypeEnum systemVersionType)
        {
            string command=string.Empty;
            switch (systemVersionType)
            {
                case SystemVersionTypeEnum.Ubuntu:
                    command = "ps aux";
                    break;
                case SystemVersionTypeEnum.CentOS:
                    command = "ps -eo user,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,cmd";
                    break;
                case SystemVersionTypeEnum.Windows:
                    break;
                default:
                    break;
            }

            if (AppRuntimeType.HasValue)
            {
                switch (AppRuntimeType.Value)
                {
                    case AppRuntimeTypeEnum.Java:
                        command += " | grep '[j]ava'";
                        break;
                    case AppRuntimeTypeEnum.Dotnet:
                        command += " | grep '[d]otnet'";
                        break;
                    default:
                        break;
                }
            }

            return command;
        }
    }
}
